package com.kaiwukj.android.ufamily.mvp.ui.page.mine.house;

import android.content.res.ColorStateList;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.app.constant.ARouterUrlKt;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.MyHouseResult;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButtonDrawable;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundRelativeLayout;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

public class MyHouseAdapter extends BaseQuickAdapter<MyHouseResult, BaseViewHolder> {

    private boolean isPick = false;

    public MyHouseAdapter() {
        super(R.layout.item_house_mine, new ArrayList<>());
    }

    public MyHouseAdapter(boolean isPick) {
        this();
        this.isPick = isPick;
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, MyHouseResult itemResult) {
        QMUIRoundRelativeLayout groupItem = holder.getView(R.id.item);
        QMUIRoundButton btnFlag = holder.getView(R.id.btn_flag);
        TextView tvHouseName = holder.getView(R.id.tv_house_name);
        TextView tvHouseAddress = holder.getView(R.id.tv_address);
        QMUIRoundButton btnManager = holder.getView(R.id.btn_manager);
        QMUIRoundButtonDrawable drawable = (QMUIRoundButtonDrawable) groupItem.getBackground();

        tvHouseName.setText(itemResult.getCommunityName());
        tvHouseAddress.setText(itemResult.getGroupAddress());

        if (isPick) btnManager.setVisibility(View.GONE);

        if (itemResult.getType() == 1) {
            btnManager.setOnClickListener(v -> ARouter.getInstance().build(ARouterUrlKt.MyHouseManagerUrl)
                    .withInt("roomId", itemResult.getRoomId())
                    .withString("address", itemResult.getGroupAddress())
                    .navigation());
        } else if (itemResult.getType() == 2) {
            btnFlag.setText("租户");
            btnFlag.setBgData(ColorStateList.valueOf(Color.parseColor("#4F82E6")));
            drawable.setBgData(ColorStateList.valueOf(Color.parseColor("#f2f2f2")));
            tvHouseName.setTextColor(ContextCompat.getColor(getContext(), R.color.gray_normal));
            tvHouseAddress.setTextColor(ContextCompat.getColor(getContext(), R.color.gray_normal));
            btnManager.setVisibility(View.GONE);
        } else {
            btnFlag.setText("家属");
            btnFlag.setBgData(ColorStateList.valueOf(Color.parseColor("#FDB832")));
            drawable.setBgData(ColorStateList.valueOf(Color.parseColor("#f2f2f2")));
            tvHouseName.setTextColor(ContextCompat.getColor(getContext(), R.color.gray_normal));
            tvHouseAddress.setTextColor(ContextCompat.getColor(getContext(), R.color.gray_normal));
            btnManager.setVisibility(View.GONE);
        }

    }
}
